/*
 *  Copyright (c) 2013 The CCP project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a Beijing Speedtong Information Technology Co.,Ltd license
 *  that can be found in the LICENSE file in the root of the web site.
 *
 *   http://www.yuntongxun.com
 *
 *  An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */
package com.monkeygroup.mygoplus.ecchat.ui.chatting;

import android.content.Context;

import com.monkeygroup.mygoplus.MyGoApplication;
import com.monkeygroup.mygoplus.R;
import com.monkeygroup.mygoplus.ecchat.common.CCPAppManager;
import com.monkeygroup.mygoplus.ecchat.ui.SDKCoreHelper;

import java.util.ArrayList;
import java.util.List;

/**
 * 聊天插件功能控制器
 *
 * @author Jorstin Chan@容联•云通讯
 * @version 4.0
 * @date 2014-12-10
 */
public class AppPanelControl {

    private Context mContext;

    private static boolean isShowVoipCall = true;
    public int[] cap = new int[]{R.string.app_panel_pic,
            R.string.app_panel_tackpic, R.string.app_panel_file, R.string.app_panel_location};
    public int[] capVoip = new int[]{R.string.app_panel_pic,
            R.string.app_panel_tackpic, R.string.app_panel_file,
            R.string.app_panel_voice, R.string.app_panel_video, R.string.app_panel_read_after_fire, R.string.app_panel_location};
    public int[] topCat = new int[]{R.string.chat_top_invite,
            R.string.chat_top_lock, R.string.chat_top_close_mention,
            R.string.chat_top_edit_name};
    public int[] topCatVoip;
//            = new int[]{R.string.chat_top_invite,
//            R.string.chat_top_lock, R.string.chat_top_close_mention,
//            R.string.chat_top_edit_name, R.string.chat_panel_voice, R.string.chat_panel_video};

    public int[] bottomCat = new int[]{R.string.chat_panel_camera,
            R.string.chat_panel_album, R.string.chat_panel_film,
            R.string.chat_panel_share, R.string.chat_panel_position};

    /**
     *
     */
    public AppPanelControl() {
        mContext = CCPAppManager.getContext();
    }

    /**
     * 單聊初始化頭部面板數據
     **/
    public void initchatTopPanelData(boolean isCancelNotice, boolean isLock) {
        if (isCancelNotice && isLock) {
            topCatVoip = new int[]{R.string.chat_top_invite,
                    R.string.chat_top_unlock, R.string.chat_top_mention,
                    R.string.chat_top_edit_name, R.string.chat_panel_voice, R.string.chat_panel_video};
        } else if (isCancelNotice) {
            topCatVoip = new int[]{R.string.chat_top_invite,
                    R.string.chat_top_lock, R.string.chat_top_mention,
                    R.string.chat_top_edit_name, R.string.chat_panel_voice, R.string.chat_panel_video};
        } else if (isLock) {
            topCatVoip = new int[]{R.string.chat_top_invite,
                    R.string.chat_top_unlock, R.string.chat_top_close_mention,
                    R.string.chat_top_edit_name, R.string.chat_panel_voice, R.string.chat_panel_video};
        } else {
            topCatVoip = new int[]{R.string.chat_top_invite,
                    R.string.chat_top_lock, R.string.chat_top_close_mention,
                    R.string.chat_top_edit_name, R.string.chat_panel_voice, R.string.chat_panel_video};
        }

    }

    /**
     * 群聊初始化頭部面板數據
     **/
    public void initGroupTopPanelData(boolean isCancelNotice) {
        if (isCancelNotice) {
            topCatVoip = new int[]{R.string.chat_top_invite, R.string.chat_top_mention,
                    R.string.chat_top_edit_name, R.string.chat_top_group_call, R.string.chat_top_group_quit};
        } else {
            topCatVoip = new int[]{R.string.chat_top_invite, R.string.chat_top_close_mention,
                    R.string.chat_top_edit_name, R.string.chat_top_group_call, R.string.chat_top_group_quit};
        }
    }

    public static void setShowVoipCall(boolean isShowVoipCall) {
        AppPanelControl.isShowVoipCall = isShowVoipCall;
    }


    /**
     * @return
     */
    public List<Capability> getCapability() {
        List<Capability> capabilities = new ArrayList<Capability>();

        if (isShowVoipCall && SDKCoreHelper.getInstance().isSupportMedia()) {
            for (int i = 0; i < capVoip.length; i++) {
                Capability capability = getCapability(capVoip[i]);
                capabilities.add(capabilities.size(), capability);
            }

        } else {
            for (int i = 0; i < cap.length; i++) {
                Capability capability = getCapability(cap[i]);
                capabilities.add(capabilities.size(), capability);
            }
        }
        return capabilities;
    }

    /**
     * @return 獲取頭部操作模板的UI數據
     */
    public List<Capability> getTopCapability() {
        List<Capability> capabilities = new ArrayList<>();

        if (isShowVoipCall && SDKCoreHelper.getInstance().isSupportMedia()) {
            for (int i = 0; i < topCatVoip.length; i++) {
                Capability capability = getCapability(topCatVoip[i]);
                capabilities.add(capabilities.size(), capability);
            }

        } else {
            for (int i = 0; i < topCat.length; i++) {
                Capability capability = getCapability(topCat[i]);
                capabilities.add(capabilities.size(), capability);
            }
        }
        return capabilities;
    }

    /**
     * @return 獲取底部發送操作模板的UI數據
     */
    public List<Capability> getBottomCapability() {
        List<Capability> capabilities = new ArrayList<>();

        for (int i = 0; i < bottomCat.length; i++) {
            Capability capability = getCapability(bottomCat[i]);
            capabilities.add(capabilities.size(), capability);
        }

        return capabilities;
    }

    /**
     * @param resid
     * @return
     */
    private Capability getCapability(int resid) {
        Capability capability = null;
        switch (resid) {

            //bottom panel begin
            case R.string.chat_panel_camera:
                capability = new Capability(getContext().getString(
                        R.string.chat_panel_camera), R.drawable.btn_chat_camera_selector);
                break;
            case R.string.chat_panel_album:

                capability = new Capability(getContext().getString(
                        R.string.chat_panel_album), R.drawable.btn_chat_image_selector);
                break;
            case R.string.chat_panel_film:

                capability = new Capability(getContext().getString(
                        R.string.chat_panel_film), R.drawable.btn_chat_film_selector);
                break;
            case R.string.chat_panel_share:

                capability = new Capability(getContext().getString(
                        R.string.chat_panel_share), R.drawable.btn_chat_sharefriend_selector);
                break;
            case R.string.chat_panel_position:
                capability = new Capability(getContext().getString(
                        R.string.chat_panel_position), R.drawable.btn_chat_position_selector);
                break;

            //bottom panel begin
            case R.string.app_panel_pic:
                capability = new Capability(getContext().getString(
                        R.string.app_panel_pic), R.drawable.image_icon);
                break;
            case R.string.app_panel_tackpic:

                capability = new Capability(getContext().getString(
                        R.string.app_panel_tackpic), R.drawable.photograph_icon);
                break;
            case R.string.app_panel_file:

                capability = new Capability(getContext().getString(
                        R.string.app_panel_file), R.drawable.capability_file_icon);
                break;
            case R.string.app_panel_voice:

                capability = new Capability(getContext().getString(
                        R.string.app_panel_voice), R.drawable.voip_call);
                break;
            case R.string.app_panel_video:

                capability = new Capability(getContext().getString(
                        R.string.app_panel_video), R.drawable.video_call);
                break;
            case R.string.app_panel_read_after_fire:

                capability = new Capability(getContext().getString(
                        R.string.app_panel_read_after_fire), R.drawable.fire_msg);
                break;
            case R.string.app_panel_location:
                capability = new Capability(getContext().getString(
                        R.string.app_panel_location), R.drawable.chat_location_normal);
                break;

            //topPanel begin
            case R.string.chat_top_invite:
                capability = new Capability(getContext().getString(
                        R.string.chat_top_invite), R.drawable.btn_chat_invite_selector);
                break;
            case R.string.chat_top_lock:
                capability = new Capability(getContext().getString(
                        R.string.chat_top_lock), R.drawable.btn_chatmain_lock);
                break;
            case R.string.chat_top_close_mention:
                capability = new Capability(getContext().getString(
                        R.string.chat_top_close_mention), R.drawable.btn_chatmain_sound);
                break;
            case R.string.chat_top_unlock:
                capability = new Capability(getContext().getString(
                        R.string.chat_top_unlock), R.drawable.btn_chatmain_lock_press);
                break;
            case R.string.chat_top_mention:
                capability = new Capability(getContext().getString(
                        R.string.chat_top_mention), R.drawable.btn_chatmain_sound_press);
                break;
            case R.string.chat_top_edit_name:
                capability = new Capability(getContext().getString(
                        R.string.chat_top_edit_name), R.drawable.btn_chat_edit_selector);
                break;
            case R.string.chat_panel_voice:
                capability = new Capability(getContext().getString(
                        R.string.chat_panel_voice), R.drawable.btn_chat_call_selector);
                break;
            case R.string.chat_panel_video:
                capability = new Capability(getContext().getString(
                        R.string.chat_panel_video), R.drawable.btn_face_chat_video_selector);
                break;
            case R.string.chat_top_group_call:
                capability = new Capability(getContext().getString(
                        R.string.chat_top_group_call), R.drawable.btn_chat_call_selector);
                break;
            case R.string.chat_top_group_quit:
                capability = new Capability(getContext().getString(
                        R.string.chat_top_group_quit), R.drawable.btn_setting_delete);
                break;
            default:
                break;
        }
        capability.setId(resid);
        return capability;
    }

    /**
     * @return
     */
    private Context getContext() {
        if (mContext == null) {
            mContext = MyGoApplication.getInstance().getApplicationContext();
        }
        return mContext;
    }
}
